import { request } from '@/utils/request';
import request2 from '@/utils/request2'
import { request3 } from '@/utils/request3';
import Vue from 'vue'

// 设备列表
export function pages(data) {
	return request({
		url: '/device/pages',
		'method': 'post',
		'data': data
	})
}

// 获取图片
export function getImg(url) {
	return request({
		url: url,
		'method': 'get',
	})
}

// 黑名单
export function getHmd(data) {
	return request2({
		url: '/hmd/getBlacklistAlarmList',
		'method': 'post',
		'data': data
	})
}


// base64转file
export const base64toFile = function(dataurl, filename) {
	const formDate = new FormData();
	const arr = dataurl.split(','),
		mime = arr[0].match(/:(.*?);/)[1],
		suffix = mime.split('/')[1],
		bstr = atob(arr[1]);
	let n = bstr.length;
	const u8arr = new Uint8Array(n);
	while (n--) {
		u8arr[n] = bstr.charCodeAt(n);
	}
	if (typeof File === 'function') {
		formDate.append('file', new File([u8arr], filename, {
			type: mime
		}));
	} else {
		const blob = new Blob([u8arr.buffer], {
			type: mime
		});
		formDate.append('file', blob, filename + '.' + suffix);
		formDate.append('module', 'read');
	}
	return formDate;
};

// 文件上传
export function uploadBase64(file) {
	const formDate = new FormData();
	// const CONFIG = window.config.common;
	// const openSecurity = CONFIG.openSecurity;
	// const formDate = base64toFile(imgValue, 'img');
	formDate.append('file', file);
	formDate.append('type', "image");
	// if(openSecurity){
	//   const srcNew = imgValue.substr(imgValue.indexOf(',') + 1);
	//  /* const srcNew = imgValue;
	//  var len=imgValue.indexOf("base64,")
	//   if(len>-1){
	//  	srcNew=imgValue.substring(len+5,imgValue.length-1)
	//   } */
	//  return request({
	//    'url': '/uploadBase64',
	//    'method': 'post',
	//  	'data':{
	// 	image:srcNew
	// }
	//  })
	// }else{
	//  return request({
	//    'url': '/fileUpload',
	//    'method': 'post',
	//  	'data':formDate
	//  })
	// }
	return request3({
		'url': '/bigdata/manage/fileUpload',
		'method': 'post',
		'data': formDate,
		'config': {
			'Content-Type': 'multipart/form-data'
		}
	})
}
